package org.dtrd.modules.evaluation.entity.bean;

import cn.hutool.core.util.StrUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.dtrd.config.system.Constant;
import org.dtrd.modules.evaluation.constant.Evaluation;
import org.dtrd.modules.evaluation.entity.po.DtrdEntEvaluationRdJob;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.Range;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @Author QR
 * @Date 2021/11/1 10:20 AM
 */
@ApiModel("马氏工作倦怠评估数据")
@Data
public class JobInfo {

    @ApiModelProperty("记录id")
    private Integer dataId;

    @ApiModelProperty("患者id")
    private Integer patientId;

    @Size(min = 15, max = 15, message = "选项数组错误")
    @NotEmpty
    @ApiModelProperty("分值列表")
    private List<@NotNull(message = "选项参数错误") @Range(min = 1,max = 7,message = "选项范围越界") Integer> input;

    @ApiModelProperty("情绪衰竭得分")
    private Integer emotion;

    @ApiModelProperty("情绪衰竭级别")
    private String emotionLevel;

    @ApiModelProperty("玩世不恭得分")
    private Integer attitude;

    @ApiModelProperty("玩世不恭级别")
    private String attitudeLevel;

    @ApiModelProperty("职业效能得分")
    private Integer efficacy;

    @ApiModelProperty("职业效能级别")
    private String efficacyLevel;

    @ApiModelProperty("输出内容")
    private String output;

    @ApiModelProperty("创建时间")
    private Date createTime;

    public JobInfo parseFromPo(DtrdEntEvaluationRdJob po) {
        this.setDataId(po.getDataId());
        ArrayList<Integer> answerList = new ArrayList<>(Evaluation.ProblemNum.JOB.getNum());
        String answerStr = po.getInput();
        if (!StrUtil.isBlank(answerStr)) {
            String[] answerArr = answerStr.split(",");
            for (String s : answerArr) {
                answerList.add(Integer.parseInt(s));
            }
        }
        this.setPatientId(po.getPatientId());
        this.setInput(answerList);
        this.setEmotion(po.getEmotion());
        this.setEmotionLevel(po.getEmotionLevel());
        this.setAttitude(po.getAttitude());
        this.setAttitudeLevel(po.getAttitudeLevel());
        this.setEfficacy(po.getEfficacy());
        this.setEfficacyLevel(po.getEfficacyLevel());
        this.setOutput(po.getOutput());
        this.setCreateTime(po.getCreateTime());
        return this;
    }
}
